package spolipar.bitcoin.bot;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import spolipar.bitcoin.bot.data.DataFetcherTask;
import spolipar.bitcoin.bot.data.LiveDataStorage;
import spolipar.bitcoin.bot.data.MarketDataType;
import spolipar.bitcoin.bot.data.bitstamp.BitstampDataFetcher;

public class ServletInit implements ServletContextListener {

    private DataFetcherTask m_bitstampMd;

    public void contextInitialized(ServletContextEvent sce) {
        if ((m_bitstampMd == null) || (!m_bitstampMd.isAlive())) {
        	LiveDataStorage.init();
        	m_bitstampMd =  new DataFetcherTask(new BitstampDataFetcher(),
            		new MarketDataType[] { MarketDataType.DEEP},
            		"Bitstamp Md",
            		1020l);
        	m_bitstampMd.start();
        }
    }

	public void contextDestroyed(ServletContextEvent sce) {
		try {
			m_bitstampMd.interrupt();
		} catch (Exception ex) {
		}
	}

}